package net.ojbk.study.twobox.service;

import net.ojbk.study.twobox.beans.po.Class;
import net.ojbk.study.twobox.beans.po.Lessontype;
import net.ojbk.study.twobox.dao.ClassMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

/**
 * Created with IntelliJ IDEA.
 * User: twobox
 * Date: 2019/4/14
 * Time: 19:59
 * Description: No Description
 */
@Service
public class LessontypeService extends SupperService<Lessontype> {
    @Autowired
    ClassMapper classMapper;

    /**
     * 增
     *
     * @param o
     * @param br
     */
    @Override
    public void addOne(Lessontype o, BindingResult br) throws Exception {
        this.validated(br, Lessontype.class);
        this.dao.insert(o);
    }

    /**
     * 删
     *
     * @param id
     */
    @Override
    public void deleteOne(int id) throws Exception {
        Class aClass = new Class();
        aClass.setLessontypeid(id);

        if (classMapper.selectCount(aClass) >= 1)
            throw new Exception("班级表中还有本课程！！！");

        this.dao.deleteByPrimaryKey(id);
    }

    /**
     * 改
     *
     * @param o
     * @param br
     */
    @Override
    public void updateOne(Lessontype o, BindingResult br) throws Exception {
        this.validated(br, Lessontype.class);
        this.dao.updateByPrimaryKeySelective(o);
    }
}
